package com.dw.etl.core.service;

import com.dw.etl.common.util.UUIDUtil;
import  com.dw.etl.common.vo.PaginationVO;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import com.dw.etl.core.api.EtlLogHandbatchItemService;
import com.dw.etl.core.mapper.EtlLogHandbatchItemMapper;
import com.dw.etl.core.bean.model.EtlLogHandbatchItem;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;

/**
 * etlLogHandbatchItem服务实现类
 * Created by hozeData on 2021/07/21.
 */
@Service
@Transactional
public class EtlLogHandbatchItemServiceImpl implements EtlLogHandbatchItemService{

    private static final Logger LOGGER = LoggerFactory.getLogger(EtlLogHandbatchItemServiceImpl.class);

    @Autowired
    private EtlLogHandbatchItemMapper etlLogHandbatchItemMapper;

    @Override
    public int insert(EtlLogHandbatchItem etlLogHandbatchItem) {
        if(StringUtils.isEmpty(etlLogHandbatchItem.getIdHandbatchItem())){
            String uuid32 = UUIDUtil.getUUID32();
            etlLogHandbatchItem.setIdHandbatchItem(uuid32);
        }
        return etlLogHandbatchItemMapper.insert(etlLogHandbatchItem);
    }

    @Override
    public int insertSelective(EtlLogHandbatchItem etlLogHandbatchItem)  {
        if(StringUtils.isEmpty(etlLogHandbatchItem.getIdHandbatchItem())){
            String uuid32 = UUIDUtil.getUUID32();
            etlLogHandbatchItem.setIdHandbatchItem(uuid32);
        }
        return etlLogHandbatchItemMapper.insertSelective(etlLogHandbatchItem);
    }

    @Override
    public int deleteById(String idHandbatchItem)  {
        return etlLogHandbatchItemMapper.deleteByPrimaryKey(idHandbatchItem);
    }

    @Override
    public int updateByIdSelective(EtlLogHandbatchItem etlLogHandbatchItem)  {

        return etlLogHandbatchItemMapper.updateByPrimaryKeySelective(etlLogHandbatchItem);
    }

    @Override
    public int updateById(EtlLogHandbatchItem etlLogHandbatchItem)  {
        return etlLogHandbatchItemMapper.updateByPrimaryKey(etlLogHandbatchItem);
    }

    @Override
    public EtlLogHandbatchItem getById(String idHandbatchItem)  {
        return etlLogHandbatchItemMapper.selectByPrimaryKey(idHandbatchItem);
    }

    @Override
    public List<EtlLogHandbatchItem> findByModel(EtlLogHandbatchItem etlLogHandbatchItem)  {
        return etlLogHandbatchItemMapper.findByModel(etlLogHandbatchItem);
    }

    @Override
    public PaginationVO<EtlLogHandbatchItem> findPageByModel(EtlLogHandbatchItem etlLogHandbatchItem, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum == null? 1 : pageNum, pageSize == null? 10 : pageSize);
        List<EtlLogHandbatchItem> quesList = etlLogHandbatchItemMapper.findByModel(etlLogHandbatchItem);
        PageInfo<EtlLogHandbatchItem> pageInfo = new PageInfo<>(quesList);
        PaginationVO<EtlLogHandbatchItem> paginationVo = new PaginationVO(pageInfo.getTotal(), pageInfo.getList());
        return paginationVo;
    }

    @Override
    public void insertList(List<EtlLogHandbatchItem> handbatchItemList) {

    }
}
